using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace LeadTracker.Models
{
	[ImmutableObject(true)]
	public class EditorToken //: IComparable<EditorToken>, IComparable, IEquatable<EditorToken>
	{


		readonly int? m_EditorKey;

		readonly string m_FirstName;

		readonly string m_LastName;

		public EditorToken(int editorKey, string firstName, string lastName)
		{
			m_EditorKey = editorKey;
			m_FirstName = firstName;
			m_LastName = lastName;
		}

		public EditorToken(IDictionary<string, object> fields)
		{
			CopyValue(fields, "EditorKey", ref m_EditorKey);
			CopyValue(fields, "FirstName", ref m_FirstName);
			CopyValue(fields, "LastName", ref m_LastName);
		}

		static void CopyValue<T>(IDictionary<string, object> fields, string fieldName, ref T target)
		{
			if (fields.ContainsKey(fieldName))
			{
				object fieldValue = fields[fieldName];
				if (fieldValue != null && fieldValue != DBNull.Value)
					target = (T)fieldValue;
			}
		}


		public int? PrimaryKey
		{
			get { return m_EditorKey; }
		}


		public int? EditorKey
		{
			get { return m_EditorKey; }
		}


		public string FirstName
		{
			get { return m_FirstName; }
		}


		public string LastName
		{
			get { return m_LastName; }
		}

		public string FullName
		{
			get { return FirstName + " " + LastName; }
		}

		public override string ToString()
		{
			return FullName;
		}

		//public int CompareTo(EditorToken other)
		//{
		//	if (other == null)
		//		return 1;

		//	return FullName.CompareTo(other.FullName);
		//}

		//int IComparable.CompareTo(object obj)
		//{
		//	if (obj == null)
		//		return 1;

		//	if (!(obj is EditorToken))
		//		throw new ArgumentException("Expected a EditorToken", "obj");

		//	return CompareTo((EditorToken)obj);
		//}



		//public bool Equals(EditorToken other)
		//{
		//	if(other == null)
		//		return false;

		//	return FullName.Equals(other.FullName);
		//}

		//public override bool Equals(object obj)
		//{
		//	if (obj == null)
		//		return false;

		//	if (!(obj is EditorToken))
		//		return false;

		//	return Equals((EditorToken)obj);
		//}

		//public override int GetHashCode()
		//{
		//	return FullName.GetHashCode();
		//}
	}
}
